
<?php
require_once '../../../library/fungsi.lib.php';

$sdate = !isset($_GET["sdate"]) ? 0 : anti_injection($_GET["sdate"]);
$edate = !isset($_GET["edate"]) ? 0 : anti_injection($_GET["edate"]);
$stat = !isset($_GET["stat"]) ? 0 : anti_injection($_GET["stat"]);


?>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Laporan Transaksi</title>
             <link rel="stylesheet" type="text/css" href="<?php echo URLHOST; ?>asset/css/astyle.css" />
        </head>
        <body>
            <div div style="border:0;padding:0;margin:5px;font-family:Tahoma,Geneva,sans-serif;font-size:11px;width:650px;line-height:18px">
                <table width="650px" cellspacing="0" cellpadding="0" border="0">
                  
                        <tr>
                            <td>
                                <div style="background-color:#e1ecf9;padding:5px 10px;border:1px solid #bfd7ff;width:1000px">
                                    <div style="float:left;padding:5px"><img src="<?php echo URLHOST; ?>asset/css/img/logo.jpg"></div>
                                    <div align="center" style="float:center;font-size:15px;padding-top:10px;">
                                        <h2>LAPORAN PENJUALAN ONLINE E-RIDER </h2> <br/>PERIODE <?php echo $sdate ; echo " s/d "; echo $edate;?> </div>
                                    <div style="clear:both"></div>
                                </div>
                               <table width="100%;" cellspacing="0" cellpadding="3" border="0" style="text-align:left;font-size:11px;line-height:15px;margin-top:5px">
                               <div style="float:center;font-size:25px;padding-top:10px;padding-right:5px">
                             <tr><th>No</th><th>Invoice No</th><th>No.Unik</th><th>Tanggal Order</th><th>No. Resi</th><th>Konsumen</th><th>Telepon</th><th>Email</th><th>Status</th><th>Ongkos Kirim</th><th>Net Items</th><th>Total</th><th>NetTotal</th></tr>
		                              <?php
									 	   $sdate = !isset($_GET["sdate"]) ? 0 : anti_injection($_GET["sdate"]);
											$edate = !isset($_GET["edate"]) ? 0 : anti_injection($_GET["edate"]);
											$details = !isset($_GET["details"]) ? 1 : anti_injection($_GET["details"]);
											$sql_trx="SELECT trx_id,tr_x.trx_kodeunik, tr_x.trx_total, tr_x.trx_angkaunik, 
											          tr_x.trx_waktu, tr_x.trx_noresi, tr_x.trx_nama, tr_x.trx_notelp, tr_x.trx_email, 
													  tr_x.trx_status,tr_x.trx_ongkir, sum( tr_d.trd_jumlah ) AS trd_jumlah, sum( tr_d.trd_harga ) AS trd_harga
													  FROM tr_x
													  INNER JOIN tr_d ON tr_d.trd_trx_id = tr_x.trx_id
													  WHERE tr_x.trx_status LIKE '$stat%'
													  AND tr_x.trx_waktu BETWEEN '$sdate' and '$edate'
													  GROUP BY trx_angkaunik, tr_x.trx_kodeunik, tr_x.trx_nama, tr_x.trx_notelp, tr_x.trx_email
													  ORDER BY tr_x.trx_kodeunik, tr_x.trx_waktu, tr_x.trx_noresi, tr_x.trx_nama, tr_x.trx_notelp, tr_x.trx_email, tr_x.trx_status, 
													           tr_x.trx_ongkir, tr_d.trd_jumlah, tr_d.trd_harga";
											/*$sql_trx = "SELECT * FROM tr_x WHERE trx_status like '$stat%' and trx_waktu between '$sdate' and '$edate' ";*/
											$hasil_trx = mysql_query($sql_trx);
									  		$no = 1;
											while ($row = mysql_fetch_array($hasil_trx)) {
									
												$harga = format_rupiah($row["trx_total"]);
												$ongkir = format_rupiah($row["trx_ongkir"]);
												$subtotal = format_rupiah($row["trd_harga"]);
												echo "<tr><td>" . $no .  "</td>";
												echo " <td><b>" . $row["trx_kodeunik"] . "</b></td>";
												echo " <td align=center>" . $row["trx_angkaunik"] . "</td>";
												echo " <td>" . get_format_waktu_full( $row["trx_waktu"]) . "</td>";
												if($row['trx_noresi']!=""){
													echo " <td align=center>" . $row["trx_noresi"] . "</td>";
												}else{
													echo " <td align=center>" .'-'. "</td>";
												}
												echo " <td>" . strtoupper( $row["trx_nama"] ). "</td>";
												echo " <td>" . $row["trx_notelp"] . "</td>";
												echo " <td>" . $row["trx_email"] . "</td>";
												echo " <td>" . get_status_transaksi($row["trx_status"]) . "</td>";
												echo " <td align=right>" . $ongkir . "</td>";
												echo " <td align=center>" . $row["trd_jumlah"] ."</td>";
												echo " <td align=right>" . $subtotal ."</td>";
												echo " <td align=right><b>" . $harga . "</b>";
												/*details*/
										
												
													
													echo " <tr align=right><td colspan=10 >";
														echo "<h3>Details Order Invoice No : <u>" . $row["trx_kodeunik"] ."</u></h3>";
												      echo " <table>";
																echo "  <tr><th>No</th><th>Nama Produk</th><th>Jumlah</th><th>Subtotal</th><th>Ukuran</th><th>Berat</th>";
																								
																$tampil = mysql_query("SELECT produks.produk_nama, sum(tr_d.trd_jumlah) as trd_jumlah, sum(tr_d.trd_harga)trd_harga, tr_d.trd_ukuran, tr_d.trd_berat
																						FROM tr_d
																						INNER JOIN produks ON produk_id = tr_d.trd_produk_id
																						INNER JOIN tr_x ON tr_x.trx_id = tr_d.trd_trx_id
																						WHERE tr_x.trx_id = '" . $row["trx_id"] . "'
																						group by produks.produk_nama, tr_d.trd_ukuran, tr_d.trd_berat
order by tr_x.trx_waktu desc
																						");
														
																$nos = 1;
																while ($rows = mysql_fetch_array($tampil)) {
														
																	$harga = format_rupiah($rows["trd_harga"]);
																	echo "<tr><td>$nos</td>";
																	echo " <td>" . strtoupper($rows["produk_nama"]) . "</td>";
																	echo " <td align=center>" . $rows["trd_jumlah"] . "</td>";
																	echo " <td align=right>" . $harga . "</td>";
																	echo " <td align=center>" . strtoupper($rows["trd_ukuran"]) . "</td>";
																	echo " <td align=center>" . $rows["trd_berat"] . "</td>";
																	echo " </tr>";
																	$nos++;
																}
																echo " </table>";
																echo " </tr>";
												echo "</td>";
												
												echo " </tr>";
												$no++;
											}
											$total = mysql_query ("SELECT sum(trx_total) as Gtotal FROM tr_x WHERE trx_status like '$stat%' and trx_waktu between '$sdate' and '$edate'");
											 $row = mysql_fetch_array($total);
											echo " <tr align=right><td colspan=12 ><h2>Grand Total</h2><td><h2>"  .  format_rupiah ($row["Gtotal"]). "</h2> </td></tr> ";
									  ?>      
       
                                    <div style="clear:both"></div>
                                
                            </td>
                        </tr>
                  
                </table>
                </div>
            </div>
        </body>
        <script language="JavaScript">
			window.print()
		</script>
    </html>
    <?php

?>